﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Deployment.Compression;

namespace MsiValidator
{
    public partial class Options : Form
    {
        public Options()
        {
            InitializeComponent();
        }

        private void Options_Load(object sender, EventArgs e)
        {
            switch (MsiValidator.compressionLevel)
            {
                case CompressionLevel.Normal:
                    radioButtonCompressionMSZIP.Checked = true;
                    break;
                case CompressionLevel.Max:
                    radioButtonCompressionLZX.Checked = true;
                    break;
                case CompressionLevel.None:
                    radioButtonCompressionNone.Checked = true;
                    break;
                default:
                    radioButtonCompressionMSZIP.Checked = true;
                    break;
            }

            textBoxTemporaryFolder.Text = MsiValidator.tempFolder;
        }

        private void buttonOptionsOK_Click(object sender, EventArgs e)
        {
            if (radioButtonCompressionMSZIP.Checked == true)
            {
                MsiValidator.compressionLevel = CompressionLevel.Normal;
            }
            if (radioButtonCompressionLZX.Checked == true)
            {
                MsiValidator.compressionLevel = CompressionLevel.Max;
            }
            if (radioButtonCompressionNone.Checked == true)
            {
                MsiValidator.compressionLevel = CompressionLevel.None;
            }

            if (Directory.Exists(textBoxTemporaryFolder.Text))
            {
                MsiValidator.tempFolder = textBoxTemporaryFolder.Text;
            }

            this.Close();
        }

        private void buttonOptionsCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonBrowseTempFolder_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                textBoxTemporaryFolder.Text = folderBrowserDialog.SelectedPath;
            }
        }
    }
}
